import { Link, browserHistory } from 'dva/router';
import { Toast } from 'antd-mobile';
import cookie from 'react-cookie';
import qs from 'qs';

export function getUserId() {
	let userId = cookie.load('userId')
	
	// // mock
	// return '3';
	if(!userId) {
		Toast.info('登录失效，请重新登录!', 1)
		browserHistory.push('/login')
	} else {
		return userId
	}
}

export function getUserName() {
	let userId = cookie.load('userName')
	
	if(!userId) {
		Toast.info('登录失效，请重新登录!', 1)
		browserHistory.push('/login')
	} else {
		return userId
	}
}
export function loginout() {
	cookie.remove('userName')
	cookie.remove('userId')
	
	browserHistory.push('/login')
}

export function getSearch(location) {
    let searchParm = location.search.replace('?', '')
    searchParm = qs.parse(searchParm)
    return searchParm
}